package cn.zy.company.servlet;

import cn.zy.company.entity.Work;
import cn.zy.company.service.WorkService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/showWork")
public class ShowWorkServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String id = req.getParameter("id");
            WorkService workService=new WorkService();
            if (id != null && id != "") {
                Work work = workService.findById(Integer.valueOf(id));
                req.setAttribute("data",work);
                req.getRequestDispatcher("WEB-INF/jsp/showWork.jsp").forward(req, resp);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
